
package com.hospital.phyexam.controller;

import com.alibaba.fastjson.JSONObject;
import com.hospital.phyexam.service.PhyexamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping(value = "/phyexam")
public class PhyexamController {
@Autowired
    PhyexamService phyexamService;

    @RequestMapping(value = "/all",produces = "application/json;charset=utf-8",method = RequestMethod.GET)
    @ResponseBody
    public String getAllExam(){
        return phyexamService.getAllBatch();
    }

    @RequestMapping(value = "/batch",produces = "application/json;charset=utf-8",method = RequestMethod.POST)
    @ResponseBody
    public String getByBatchName(@RequestBody String data){
        String string=JSONObject.parseObject(data).getString("phyExmBatchName");
        return phyexamService.selectByBatchName(string);
    }

    @RequestMapping(value = "/delete",produces = "application/json;charset=utf-8",method = RequestMethod.POST)
    @ResponseBody
    public String delete(@RequestBody String data){
        Integer batchId=Integer.parseInt(JSONObject.parseObject(data).getString("id"));
        Integer proId=Integer.parseInt(JSONObject.parseObject(data).getString("proId"));
        return phyexamService.delete(proId,batchId);
    }

    @RequestMapping(value = "/update",produces = "application/json;charset=utf-8",method = RequestMethod.POST)
    @ResponseBody
    public String update(@RequestBody String data){
        Integer batchId=Integer.parseInt(JSONObject.parseObject(data).getString("id"));
        Integer proId=Integer.parseInt(JSONObject.parseObject(data).getString("proId"));
        String string=JSONObject.parseObject(data).getString("proName");
        return phyexamService.update(batchId,proId,string);
    }
}

